package com.egd.imapp.contoller.activity.contact;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.egd.imapp.R;
import com.egd.imapp.contoller.activity.chat.SingleChatActivity;
import com.egd.imapp.contoller.activity.chat.VoiceActivity;
import com.hyphenate.easeui.domain.EaseUser;
import com.hyphenate.easeui.widget.EaseImageView;
import com.hyphenate.easeui.widget.EaseTitleBar;

public class ContactDetailActivity extends AppCompatActivity implements View.OnClickListener {
    private EaseTitleBar mEaseTitleBar;
    private EaseImageView mAvatarUser;
    private TextView mTvName;
    private TextView mBtnChat;
    private TextView mBtnVoice;
    private TextView mBtnVideo;
    
    private EaseUser mUser;
    

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contact_detail);
        
        initView();

        initData();

        initListener();
    }

    private void initListener() {
        mEaseTitleBar.setOnBackPressListener(new EaseTitleBar.OnBackPressListener() {
            @Override
            public void onBackPress(View view) {
                onBackPressed();
            }
        });

        mBtnChat.setOnClickListener(this);
        mBtnVoice.setOnClickListener(this);
        mBtnVideo.setOnClickListener(this);
    }

    private void initData() {
        Intent intent = getIntent();
        mUser = (EaseUser) intent.getSerializableExtra("user");

        mUser.setSign(mUser.getUsername());
        mUser.setNickname(mUser.getUsername());
        mUser.setExt(mUser.getUsername());

        mAvatarUser.setImageResource(R.drawable.ease_default_avatar);

        mTvName.setText(mUser.getUsername());
    }

    private void initView() {
        mEaseTitleBar = findViewById(R.id.title_bar_contact_detail);
        mAvatarUser = findViewById(R.id.avatar_user);
        mTvName = findViewById(R.id.tv_name);
        mBtnChat = findViewById(R.id.btn_chat);
        mBtnVoice = findViewById(R.id.btn_voice);
        mBtnVideo = findViewById(R.id.btn_video);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.btn_chat :
                Intent intent = new Intent(ContactDetailActivity.this, SingleChatActivity.class);
                intent.putExtra("user", mUser);
                startActivity(intent);
                Toast.makeText(ContactDetailActivity.this, " 服务完善中 btn_chat....", Toast.LENGTH_SHORT).show();

//                ChatActivity.actionStart(mContext, mUser.getUsername(), EaseConstant.CHATTYPE_SINGLE);
                break;
            case R.id.btn_voice :
                Intent intent1 = new Intent(ContactDetailActivity.this, VoiceActivity.class);
                startActivity(intent1);
                Toast.makeText(ContactDetailActivity.this, " 服务完善中 btn_voice....", Toast.LENGTH_SHORT).show();

//                EaseCallKit.getInstance().startSingleCall(EaseCallType.SINGLE_VOICE_CALL,mUser.getUsername(),null, VideoCallActivity.class);
                break;
            case R.id.btn_video :
                Toast.makeText(ContactDetailActivity.this, " 服务完善中 btn_video....", Toast.LENGTH_SHORT).show();
//                EaseCallKit.getInstance().startSingleCall(EaseCallType.SINGLE_VIDEO_CALL,mUser.getUsername(),null, VideoCallActivity.class);
                break;
        }
    }
}